﻿using System;
using System.Data;
using System.Collections.Generic;
using Things.Common;
using Things.Model;
using Things.DALFactory;
using Things.IDAL;
namespace Things.BLL
{
	/// <summary>
	/// GoodsPrice
	/// </summary>
	public partial class GoodsPrice
	{
		private readonly IGoodsPrice dal=DataAccess.CreateGoodsPrice();
		public GoodsPrice()
		{}
		#region  Method
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(Guid ID)
		{
			return dal.Exists(ID);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(Things.Model.GoodsPrice model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(Things.Model.GoodsPrice model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(Guid ID)
		{
			
			return dal.Delete(ID);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			return dal.DeleteList(IDlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public Things.Model.GoodsPrice GetModel(Guid ID)
		{
			
			return dal.GetModel(ID);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public Things.Model.GoodsPrice GetModelByCache(Guid ID)
		{
			
			string CacheKey = "GoodsPriceModel-" + ID;
			object objModel = Things.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(ID);
					if (objModel != null)
					{
						int ModelCache = Things.Common.ConfigHelper.GetConfigInt("ModelCache");
						Things.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (Things.Model.GoodsPrice)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Things.Model.GoodsPrice> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<Things.Model.GoodsPrice> DataTableToList(DataTable dt)
		{
			List<Things.Model.GoodsPrice> modelList = new List<Things.Model.GoodsPrice>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				Things.Model.GoodsPrice model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new Things.Model.GoodsPrice();
					if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="")
					{
						model.ID=new Guid(dt.Rows[n]["ID"].ToString());
					}
					if(dt.Rows[n]["GoodsID"]!=null && dt.Rows[n]["GoodsID"].ToString()!="")
					{
						model.GoodsID=new Guid(dt.Rows[n]["GoodsID"].ToString());
					}
					if(dt.Rows[n]["GoodsPriceType"]!=null && dt.Rows[n]["GoodsPriceType"].ToString()!="")
					{
					model.GoodsPriceType=dt.Rows[n]["GoodsPriceType"].ToString();
					}
					if(dt.Rows[n]["GoodsCurrentPrice"]!=null && dt.Rows[n]["GoodsCurrentPrice"].ToString()!="")
					{
						model.GoodsCurrentPrice=decimal.Parse(dt.Rows[n]["GoodsCurrentPrice"].ToString());
					}
					if(dt.Rows[n]["GoodsStandPrice"]!=null && dt.Rows[n]["GoodsStandPrice"].ToString()!="")
					{
						model.GoodsStandPrice=decimal.Parse(dt.Rows[n]["GoodsStandPrice"].ToString());
					}
                    if (dt.Rows[n]["ShangPinBianHao"] != null && dt.Rows[n]["ShangPinBianHao"].ToString() != "")
                    {
                        model.ShangPinBianHao = int.Parse(dt.Rows[n]["ShangPinBianHao"].ToString());
                    }
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}


        /// <summary>
        /// 获得对象
        /// </summary>
        /// <param name="ShangPinBianHao"></param>
        /// <returns></returns>
        public Things.Model.GoodsPrice GetModel(int ShangPinBianHao)
        {
            return dal.GetModel(ShangPinBianHao);
        }

		#endregion  Method
	}
}

